package view.servlet.knowledge;

import com.alibaba.fastjson.JSON;
import pojo.Knowledge;
import pojo.User;
import pojo.vo.Message;
import service.KnowledgeService;
import service.impl.KnowledgeServiceImpl;
import util.DateUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author wq3stone
 */

@WebServlet("/updateKlg")
public class UpdateKlg extends HttpServlet {
    KnowledgeService knowledgeService = new KnowledgeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        Knowledge knowledge = new Knowledge();
        knowledge.setId(Integer.valueOf(req.getParameter("id")));
        knowledge.setTitle(req.getParameter("title"));
        knowledge.setCategory(req.getParameter("category"));
        knowledge.setKeyword(req.getParameter("keyword"));
        knowledge.setContent(req.getParameter("content"));
        knowledge.setDate(DateUtil.strToDate(req.getParameter("date")));
        Message message = knowledgeService.updateKlg(knowledge);
        resp.getWriter().print(JSON.toJSONString(message));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
